import { _decorator, Component, director, Node, Sprite } from 'cc';
import { emits } from '../data/enums';
import { gameConfig } from '../data/gameConfig';
import { loadRes } from '../utils/loadRes';
const { ccclass, property } = _decorator;

@ccclass('box')
export class box extends Component {
    @property(Sprite)
    boxSprite: Sprite = null;
    position: number[] = [0, 0];
    type: number = 0; //0不能推1可以
    protected onEnable(): void {
        
    }

    init() {
        this.boxSetPos();
        this.boxSetSprite();
    }
    onDestroy() {
        director.off(emits.boxPush)
    }
    boxSetPos() {
        //坐标值*方块大小-游戏原点 设置左下角为[0,0]
        this.node.setPosition(this.position[0] * gameConfig.blockSize - gameConfig.gameOrigin[0], this.position[1] * gameConfig.blockSize - gameConfig.gameOrigin[1]);
    }
    boxSetSprite(){
        if(this.type==0){
            this.boxSprite.spriteFrame = loadRes.ins.getSpriteFrame('box1');
        }else if(this.type==1){
            this.boxSprite.spriteFrame = loadRes.ins.getSpriteFrame('box2');
        }
    }
}


